#include "wap_imgbtn.h"
#include "wa_wm.h"
#include "wa_win.h"
#include "wa_screen.h"
#include "wa_imgbtn.h"
#include "wap.h"

static void wap_imgbtn_create(void);
static void wap_imgbtn_del(void);
static void wap_imgbtn_callback(wa_sign* sign);

wa_screen_obj wap_imgbtn_screen = 
{
	.id = WAP_WIN_IMGBTN_ID,
	.create = wap_imgbtn_create,
	.del = wap_imgbtn_del,
};

wa_obj* wap_imgbtn_win;
wa_obj* wap_imgbtn_imgbtn;

extern wa_bitmap img_btn;

void wap_imgbtn_init(void)
{
	
}

static void wap_imgbtn_create(void)
{
	wap_imgbtn_win = wa_win_create(NULL);
	wa_win_set_pos(wap_imgbtn_win, 0, 0);
	wa_win_set_size(wap_imgbtn_win, WA_LCD_W, WA_LCD_H);
	wa_win_set_edge_show(wap_imgbtn_win, wa_nok);
	wa_win_set_callback(wap_imgbtn_win, wap_imgbtn_callback);
	wap_imgbtn_screen.win = wap_imgbtn_win;
	
	wap_imgbtn_imgbtn = wa_imgbtn_create(NULL);
	wa_win_add_obj(wap_imgbtn_win, wap_imgbtn_imgbtn);
	wa_obj_set_pos(wap_imgbtn_imgbtn, 46, 14);
	wa_obj_set_size(wap_imgbtn_imgbtn, 46, 36);
	wa_imgbtn_set_bitmap(wap_imgbtn_imgbtn, &img_btn);
	wa_imgbtn_set_offset_dir(wap_imgbtn_imgbtn, WA_IMGBTN_PRESS_OFFSET_RIGHT);
	wa_imgbtn_set_press_offset(wap_imgbtn_imgbtn, 10);
}

static void wap_imgbtn_del(void)
{
	wa_obj_del(wap_imgbtn_win);
}

static void _wap_imgbtn_paint(wa_obj* obj)
{
}

static void wap_imgbtn_callback(wa_sign* sign)
{
	int sign_id;
	wa_obj* obj;
	sign_id = sign->sign_id;
	obj = sign->obj_dst;

	switch (sign_id)
	{
		case WA_SIGNAL_PAINT:
		{
			_wap_imgbtn_paint(obj);
			break;
		}
		case WA_SIGNAL_NOTIFY_PARENT:
		{	
			break;
		}
		
		case WA_SIGNAL_USER_KEY_UP:
		{	
			wa_imgbtn_set_state(wap_imgbtn_imgbtn, WA_IMGBTN_STATE_UNPRESSED);
			break;
		}
		case WA_SIGNAL_USER_KEY_DOWN:
		{	
			wa_imgbtn_set_state(wap_imgbtn_imgbtn, WA_IMGBTN_STATE_PRESSED);
			break;
		}
		case WA_SIGNAL_USER_KEY_ESC:
		{	
			wa_screen_switch(WAP_WIN_MENU_ID, WA_SCREEN_SWITCH_TYPE_LEFT_TOGETHER, 500, wa_nok, wa_nok);
			break;
		}
		default:
		{
			break;
		}
	}
}

